import './detect-living-face';
import './face-compare';
import './id-card-compare';
import './invite-human-three-parties';
import './ivvr';
import './message-collect';
import './message-summary';
import './message-sure';
import './nlp';
import './option-judge';
import './request-location';
import './scan-code';
import './screen-snapshot';
import './send-deposition';
import './send-form';
import './send-page';
import './send-pdf';
import './send-rich-text';
import './send-sign';
import './send-video';
import './sign-contract';
import './silent-wating';
import './sound-reception';
import './speak-waiting';
import './summary-confirm';
import './variable-collection';
import './variable-judge';
import './waiting-read';
import './hangup';
import './scene-transfer';
import './transfer';
import './video-collect';
import './interface-call';
import './start-recording';
import './stop-recording';
import './card-collection';
import './llm';
import { InitModalMethod, ParseModalMethod } from './defination';

/**
 * 设置表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const initModalDataWithType = (nodeType = '', form = {}, workstep = {}, tts = false) => {
	if (!nodeType || !form || !workstep || !workstep.do) {
		return;
	}
	console.log('initModalDataWithType:', nodeType, form, workstep);

	form.name = workstep.name;

	if (['sendMessage', 'sendContents'].includes(nodeType)) {
		const type = workstep?.do?.data?.data?.type || workstep?.do?.data?.data?.cmd || workstep?.do?.data?.type;
		if (type === 'video') {
			return InitModalMethod['sendVideo'](form, workstep, tts);
		}
		if (type === 'page') {
			return InitModalMethod['sendPage'](form, workstep, tts);
		}
		if (type === 'richtext') {
			return InitModalMethod['sendRichText'](form, workstep, tts);
		}
		if (type === 'paper') {
			return InitModalMethod['sendPdf'](form, workstep, tts);
		}
		if (type === 'screen-snapshot') {
			return InitModalMethod['screenSnapshot'](form, workstep, tts);
		}
	}

	return InitModalMethod[nodeType](form, workstep, tts);
};

/**
 * 解析节点属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const parseModalDataWithType = (nodeType = '', form = {}, workstep = {}, tts = false) => {
	if (!nodeType) {
		return;
	}
	workstep.name = form.name;
	workstep.completed = true;
	if (['sendMessage', 'sendContents'].includes(nodeType)) {
		const type = workstep?.do?.data?.data?.type || workstep?.do?.data?.data?.cmd || workstep?.do?.data?.type;
		if (type === 'video') {
			return ParseModalMethod['sendVideo'](form, workstep, tts);
		}
		if (type === 'page') {
			return ParseModalMethod['sendPage'](form, workstep, tts);
		}
		if (type === 'richtext') {
			return ParseModalMethod['sendRichText'](form, workstep, tts);
		}
		if (type === 'paper') {
			return ParseModalMethod['sendPdf'](form, workstep, tts);
		}
		if (type === 'screen-snapshot') {
			return ParseModalMethod['screenSnapshot'](form, workstep, tts);
		}
	}
	return ParseModalMethod[nodeType](form, workstep, tts);
};
